package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.io.*;


public class Register {
    public ArrayList <Book> listOfBooks  = new ArrayList<Book>();
    Book book1 = new Book("1234","LOTR","JRR Tolkien", "Penguin");
    Book book2 = new Book("12444","White Fang","Jack London", "Penguin");
    Book book3 = new Book("1256","Runaway Jury","John Grisham", "Penguin");
    Book book4 = new Book("3456","Abduction","Robin Cook", "Illustrator");

    public ArrayList <Movie> listOfMovies  = new ArrayList<Movie>();
    Movie movie1 = new Movie("LOTR","Peter Jackson", 2003,8);
    Movie movie2 = new Movie("Casino", "Quentin Tarantino", 1995, 8);
    Movie movie3 = new Movie("Sound of Music", "Oscar Hammerstein", 1965, 9);
    Movie movie4 = new Movie("Pulp Fiction", "Quentin Tarantino", 1991, 9);

    public Register(){

       CreateSampleList();

   }
    public void CreateSampleList(){


        listOfBooks.add(book1);
        listOfBooks.add(book2);
        listOfBooks.add(book3);
        listOfBooks.add(book4);
        listOfMovies.add(movie1);
        listOfMovies.add(movie2);
        listOfMovies.add(movie3);
        listOfMovies.add(movie4);
    }

    public ArrayList getListOfBooks(){

        return listOfBooks;

    }
    public ArrayList getListOfMovies(){

        return listOfMovies;

    }

    public void DisplayBooks() {
        for(Book book:listOfBooks)
        {
            System.out.println(book.isbn + " " + book.title + " " + book.author + " " + book.publisher);

        }
    }

    public void addBook(String isbn) {


        if(isbn.equalsIgnoreCase( book1.isbn))listOfBooks.add(book1);
        else if(isbn.equalsIgnoreCase( book2.isbn))listOfBooks.add(book2);
        else if(isbn.equalsIgnoreCase( book3.isbn))listOfBooks.add(book3);
        else if(isbn.equalsIgnoreCase( book4.isbn))listOfBooks.add(book4);


        else System.out.print("Not a valid book to return !");

    }
    public void addMovie(String name) {


        if(name.equalsIgnoreCase( movie1.name))listOfMovies.add(movie1);
        else if(name.equalsIgnoreCase( movie2.name))listOfMovies.add(movie2);
        else  if(name.equalsIgnoreCase( movie3.name))listOfMovies.add(movie3);
        else  if(name.equalsIgnoreCase( movie4.name))listOfMovies.add(movie4);


        else System.out.print("Not a valid book to return !");

    }

    public void removeMovie(String name) {
        boolean flag = false;
        for(Movie tempMovie:listOfMovies)
        {
            if(tempMovie.name.equalsIgnoreCase(name))
            {
                listOfMovies.remove(tempMovie);
                System.out.println("Thank you for checking out the movie!");
                flag = true;
                break;
            }

        }
        if(flag == false){
            System.out.print("Not a valid movie!");

        }

    }
    public void removeBook(String isbn) {
        boolean flag = false;
        for(Book tempBook:listOfBooks)
        {
            if(tempBook.isbn.equalsIgnoreCase(isbn))
            {
                listOfBooks.remove(tempBook);
                System.out.println("Thank you for checking out the book!");
                flag = true;
                   break;
            }

        }
    if(flag == false){
        System.out.print("Not a valid book!");

    }

    }

    public void DisplayMovies() {

        for(Movie movie:listOfMovies)
        {
            System.out.println(movie.name + " " + movie.rating + " " + movie.year + " " + movie.director);

        }
    }
}
